package com.sectop.bank;

import com.sectop.bank.domain.OverdraftException;

public class CheckingAcc extends Account{
    private double protection;

    public CheckingAcc(double balance) {
         super(balance);
         this.protection = 0;
    }
    public CheckingAcc(double balance, double protection) {
        super(balance);
        this.protection = protection;
    }
    @Override
    public void withDraw(double atm) throws OverdraftException {

        if(protection == 0){
            if((this.getBalance() - atm) < 0){
                double Deifcit = -((this.getBalance() - atm));

                throw new OverdraftException("no overdraft protection",Deifcit);
            }else {
                balance -= atm;
//                return true;
            }
        }
         if((this.protection + this.getBalance()) - atm < 0){

             throw new OverdraftException("Insufficient funds for overdraft protection",atm);
         }else if(this.balance - atm > 0){
               this.balance -= atm;
         } else if (this.balance - atm < 0) {

             double down = this.balance - atm;
             this.balance = 0;
             protection += down;
         }
//         return true;
    }
}
